home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 3: Developer Tools / Linux Cubed Series 3 - Developer Tools.iso / devel / db / esm-3.1 / esm-3 / usr / local / sm / src / serverlib / undo / undoEntirePage.C < prev    next >
Encoding:
C/C++ Source or Header  |  1996-05-05  |  5.9 KB  |  202 lines

  1. /*
  2.  *   $RCSfile: undoEntirePage.C,v $  
  3.  *   $Revision: 1.1.1.1 $  
  4.  *   $Date: 1996/05/04 21:56:04 $      
  5.  */ 
  6. /**********************************************************************
  7. * EXODUS Database Toolkit Software
  8. * Copyright (c) 1991 Computer Sciences Department, University of
  9. *                    Wisconsin -- Madison
  10. * All Rights Reserved.
  11. *
  12. * Permission to use, copy, modify and distribute this software and its
  13. * documentation is hereby granted, provided that both the copyright
  14. * notice and this permission notice appear in all copies of the
  15. * software, derivative works or modified versions, and any portions
  16. * thereof, and that both notices appear in supporting documentation.
  17. *
  18. * THE COMPUTER SCIENCES DEPARTMENT OF THE UNIVERSITY OF WISCONSIN --
  19. * MADISON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" CONDITION.  
  20. * THE DEPARTMENT DISCLAIMS ANY LIABILITY OF ANY KIND FOR ANY DAMAGES
  21. * WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
  22. *
  23. * The EXODUS Project Group requests users of this software to return 
  24. * any improvements or extensions that they make to:
  25. *
  26. *   EXODUS Project Group 
  27. *     c/o David J. DeWitt and Michael J. Carey
  28. *   Computer Sciences Department
  29. *   University of Wisconsin -- Madison
  30. *   Madison, WI 53706
  31. *
  32. *     or exodus@cs.wisc.edu
  33. *
  34. * In addition, the EXODUS Project Group requests that users grant the 
  35. * Computer Sciences Department rights to redistribute these changes.
  36. **********************************************************************/
  37.  
  38.  
  39. #include "sysdefs.h"
  40. #include "ess.h"
  41. #include "checking.h"
  42. #include "trace.h"
  43. #include "error.h"
  44. #include "list.h"
  45. #include "tid.h"
  46. #include "io.h"
  47. #include "lock.h"
  48. #include "object.h"
  49. #include "msgdefs.h"
  50. #include "thread.h"
  51. #include "latch.h"
  52. #include "semaphore.h"
  53. #include "link.h"
  54. #include "lsn.h"
  55. #include "bf.h"
  56. #include "pool.h"
  57. #include "log.h"
  58. #include "volume.h"
  59. #include "trans.h"
  60. #include "logrecs.h"
  61. #include "logaction.h"
  62. #include "openlog.h"
  63. #include "undo.h"
  64. #include "undo_extfuncs.h"
  65. #include "bf_extfuncs.h"
  66. #include "log_extfuncs.h"
  67. #include "log_intfuncs.h"
  68. #include "util_funcs.h"
  69. #include "thread_globals.h"
  70. #include "bf_globals.h"
  71. #include "trans_globals.h"
  72. #include "sm_macro.h"
  73. #ifdef INIT_LRC_IS_LSN
  74. #    include "log_globals.h"
  75. #endif
  76.  
  77.  void
  78. undoEntirePage (
  79.  
  80.     LOGRECORDHDR        *recordHeader 
  81. )
  82. {
  83.  
  84.     GROUPLINK            *groupLink;
  85.     PID                    *pid;
  86.     LOGRECORDINFO       recordInfo;
  87. #ifdef INIT_LRC_IS_LSN
  88.     LRC                 tempLRC;
  89.     LRC                 *lrc = &tempLRC;
  90. #else
  91.     LRC                 *lrc;
  92. #endif /* INIT_LRC_IS_LSN; */
  93.     LSN                    lsn;
  94.     FORCEMARK            forceMark;
  95.     PAGETYPE            pageType;
  96.     PAGE2SIZE            page2size;
  97.     SLOTTEDPAGE            *slottedPage;
  98.     MISSINGUPDATEINFO     *missingUpdateInfo;
  99.     BOOL                actionDone;    /* Indicates whether the action
  100.                                        was ever performed on the page */
  101.  
  102.     TRPRINT(TR_IO, TR_LEVEL_1, ("lsn:%d", recordHeader->recordLSN));
  103.  
  104.     /* Remember pointer to missing update information */
  105.     missingUpdateInfo = ( ((TRANSREC*)Active->transRec)->missingUpdateInfo);
  106.  
  107.     /* get a pointer to the page for the record */
  108.     pid = &(recordHeader->actionPid);
  109.     TRPRINT(TR_IO|TR_LOG, TR_LEVEL_2, ("pid:%d", pid->page));
  110.  
  111.  
  112.     switch(recordHeader->action) {
  113.     case LOG_ACTION_ENTIRE_SLOTTED:
  114.         pageType = PAGE_SLOTTED;
  115.         page2size = SLOTTED_PAGE2SIZE;
  116.         break;
  117.     case LOG_ACTION_ENTIRE_LARGE_NODE:
  118.         pageType = PAGE_LARGENODE;
  119.         page2size = LG_PAGE2SIZE;
  120.         break;
  121.     case LOG_ACTION_ENTIRE_LARGE_DATA:
  122.         pageType = PAGE_LARGEDATA;
  123.         page2size = LGDATA_PAGE2SIZE;
  124.         break;
  125.     case LOG_ACTION_ENTIRE_BTREE_PAGE:
  126.         pageType = PAGE_INDEX;
  127.         page2size = BTREE_PAGE2SIZE;
  128.         break;
  129.     case LOG_ACTION_ENTIRE_INDEXDESC:
  130.         pageType = PAGE_INDEXDESC;
  131.         page2size = INDEXDESC_PAGE2SIZE;
  132.         break;
  133.     default:
  134.         SM_ERROR(TYPE_FATAL, esmINTERNAL);
  135.     }
  136.  
  137.     /*
  138.      *    The current implementation of this function does not support
  139.      *    undo except for slotted pages.  This is ok since all other
  140.      *    pages will be deallocated since this type of log record is
  141.      *    only used for new pages.  Slotted pages are "permanently" 
  142.      *    allocated, so they must have this operation undone.
  143.      */
  144.     if (pageType == PAGE_SLOTTED) {
  145.  
  146.         /* read in the page */
  147.         if ((groupLink = bf_ReadPage(UserBufGroup, pid, page2size, BF_SEM)) == NULL) {
  148.             SM_ERROR(TYPE_FATAL, Active->errno);
  149.         }
  150.         groupLink->pageHash->pageType = pageType;
  151.  
  152.         slottedPage = (SLOTTEDPAGE *) groupLink->bufFrame;
  153.         SM_ASSERT(LEVEL_3, pid->page == recordHeader->actionPid.page);
  154.         if (CHECK_SLOTTED_MAGIC(slottedPage)) {
  155.             SM_ERROR(TYPE_FATAL, esmBADSLOTTEDMAGIC);
  156.         }
  157.  
  158.         /* 
  159.          *    See if the action was actually done.  It must be since
  160.          *    this type of log record is only generated on the server.
  161.          */
  162.          actionDone = compareLRC(&(recordHeader->actionLRC), &(slottedPage->header.lrc) ) <= 0;
  163.         SM_ASSERT(LEVEL_3, actionDone);    
  164.  
  165.         lrc = &(slottedPage->header.lrc);
  166.  
  167.         INITPAGE(slottedPage, *pid, slottedPage->header.fid, FALSE, 0);
  168.         /*
  169.          *    record that all unique numbers are used up, since we don't
  170.          *    know what to restore this to.
  171.          */
  172.         slottedPage->header.uniqueCount = 0;
  173.  
  174.         /* increment the lrc on the page */
  175.         GENERATE_LRC(lrc);
  176.  
  177.         recordInfo.action       = LOG_ACTION_SLOTTED_PAGE_FORMAT;
  178.         recordInfo.type         = LOG_REC_TYPE_COMPENSATION;
  179.         recordInfo.imageCount   = 1;
  180.         recordInfo.actionPid    = pid;
  181.         recordInfo.actionLRC    = lrc;
  182.         recordInfo.imageSize[0] = sizeof(SLOTTEDHEADER) + sizeof(PAGESLOT);
  183.         recordInfo.imageData[0] = (VOID *) &(slottedPage->slot[0]);
  184.         recordInfo.nextUndoLSN  = recordHeader->previousLSN;
  185.         recordInfo.flags = NOFLAGS;
  186.  
  187.         if ((forceMark = writeLogRecord((TRANSREC *) Active->transRec, &recordInfo, &lsn, NOFLAGS)) < 0)  {
  188.             SM_ERROR(TYPE_FATAL, Active->errno);
  189.         }
  190.         DEPEND_LOG(groupLink->pageHash, forceMark, &lsn, lrc);
  191.  
  192.         /*
  193.          *    release the semaphore and unfix the page, dirty the page if
  194.          *    the action was done
  195.          */
  196.         signalSemaphore( &(groupLink->pageHash->semaphore) );
  197.         bf_UnfixPage(groupLink, BF_DEFAULT, actionDone);
  198.     }  
  199.  
  200.     return;
  201. }
  202.